

//
//  CcNoDataView.m
//  新项目
//
//  Created by 刘耀宗 on 2016/11/21.
//  Copyright © 2016年 刘耀宗. All rights reserved.
//

#import "CcNoDataView.h"

@implementation CcNoDataView
+(instancetype)shareNoDataView
{
    static id instance;
    static dispatch_once_t once;
    dispatch_once(&once, ^{
        instance=[[self alloc] init];
        
    });
    return instance;
    
    
}
-(UIImageView *)imageView
{
    if (_imageView == nil) {
        _imageView = [[UIImageView alloc] init];
        _imageView.image=[UIImage imageNamed:@"ic_404_date"];
    }
    return _imageView;
    
}
-(UILabel *)label
{
    if (_label == nil) {
        _label = [[UILabel alloc] init];
        _label.font=newFont(16);
        _label.textColor=CcColor(51, 51, 51);
        _label.textAlignment=NSTextAlignmentCenter;
        _label.text=@"啥都没有";
    }
    return _label;
}
-(UILabel *)label1
{
    if (_label1 == nil) {
        _label1 = [[UILabel alloc] init];
         _label1.font=newFont(16);
        _label1.textColor=CcColor(153, 153, 153);
        _label1.textAlignment=NSTextAlignmentCenter;
        _label1.text=@"请看看是否联网";
    }
    return _label1;
}
-(UIButton *)btn
{
    if (_btn == nil) {
        _btn = [[UIButton alloc] init];
        [_btn setTitle:@"再试试" forState:UIControlStateNormal];
        [_btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        [_btn setTitleColor:CcColor(51, 51, 51) forState:UIControlStateNormal];
        _btn.titleLabel.font=newFont(16);
        _btn.layer.cornerRadius=44/2;
        _btn.layer.masksToBounds=YES;
        _btn.layer.borderWidth=1;
        _btn.layer.borderColor=[[UIColor grayColor] CGColor];

        
    }
    return _btn;
    
    
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self prepareUI];
        
    }
    return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self prepareUI];
    }
    return self;
}
-(void)prepareUI
{
    NSArray *views=@[self.imageView,self.label,self.btn,self.label1];
    self.btn.hidden=YES;
    [self sd_addSubviews:views];
    
    self.imageView.sd_layout
    .centerXEqualToView(self)
    .topSpaceToView(self,50)
    .widthIs(150)
    .heightIs(150);
    
    self.label.sd_layout
    .topSpaceToView(self.imageView,16)
    .centerXEqualToView(self)
    .heightIs(25)
    .widthIs(200);
    
    self.label1.sd_layout
    .centerXEqualToView(self.label)
    .topSpaceToView(self.label,12)
    .autoHeightRatio(0);
    [self.label1 setSingleLineAutoResizeWithMaxWidth:200];
    
    self.btn.sd_layout
    .centerXEqualToView(self)
    .heightIs(44)
    .widthIs(300)
    .topSpaceToView(self.label1,16);
    
    
}
#pragma mark--页面数据为空
-(void)dataIsEmpty:(NSArray *)arr withView:(UIView *)view  andNoDataView:(CcNoDataView *)nodataView andRect:(CGRect) rect andBtnHiddne:(BOOL)hid
{
    if (arr.count==0) {
        self.imageView.image=[UIImage imageNamed:@"ic_404_date"];
        [view addSubview:nodataView];
        [nodataView bringSubviewToFront:view];
        nodataView.btn.hidden=hid;
        nodataView.label.text=@"啥都没有";
        nodataView.frame=rect;//
         nodataView.label1.hidden=YES;
        [nodataView.btn setTitle:@"立即刷新" forState:UIControlStateNormal];

        nodataView.myBlock=^{
            
            
            
        };
    }else
    {
        [nodataView removeFromSuperview];
//        self.tableView.mj_footer.hidden=NO;
    }
    
}
#pragma mark--无网络页面
-(void)noNetwithView:(UIView *)view  andNoDataView:(CcNoDataView *)nodataView andRect:(CGRect) rect andBtnHiddne:(BOOL)hid
{
       [nodataView removeFromSuperview];
        [view addSubview:nodataView];
        [nodataView bringSubviewToFront:view];
        nodataView.btn.hidden=hid;
    nodataView.label1.hidden=NO;
        self.imageView.image=[UIImage imageNamed:@"ic_404_wifi"];
        nodataView.label.text=@"网络不好";
      nodataView.label1.text=@"请看看是否联网~";
        nodataView.frame=rect;//
          [nodataView.btn setTitle:@"重新加载" forState:UIControlStateNormal];
        nodataView.myBlock=^{
            
            
            
        };
 
    
}
-(void)btnClick
{
    if (self.myBlock!=nil) {
        self.myBlock();
    }
    
    
}


@end
